import request from '../axios'
import { LEVELS } from '../const'

// 测试登录
export function testLogin (userId, pid) {
  const url = '/api/user/test/login'
  return request.post(url, { userId, pid })
}

// 微信登录
export function wxLogin (code, pid) {
  const url = '/api/user/wx/login'
  return request.post(url, { code, pid })
}

// 业务员、药店注册
export function register (user) {
  const url = '/api/user/h5/register'
  const data = {
    ...user,
    Loading: true
  }
  return request.post(url, data)
}

// 获取用户名字
export function getName (id) {
  const url = `/api/user/name/${id}`
  return request.get(url)
}

// // 获取所有的激活的药店
// export function getShop () {
//   const url = '/api/user/shop'
//   return request.get(url)
// }

// 获取团队下面激活的业务员
export function getUsers () {
  const lv = LEVELS.BUS
  const url = `/api/user/lv/${lv}`
  const params = {
    status: 0
  }
  return request.get(url, { params })
}

/**
 * 找出下级
 */
export function sTop () {
  const url = '/api/user/list'
  return request.get(url)
}

/**
 * 找出所有下级的下级
 */
export function sumByTop (startDate, endDate, uid) {
  const url = '/api/user/sum'
  const params = { startDate, endDate, uid }
  return request.get(url, { params })
}

/**
 * 找出业务员级以上的下级
 * @returns {Promise<AxiosResponse<any>>}
 */
export function gtBusUser () {
  const url = '/api/user/top/lv/gt/bus'
  return request.get(url)
}

/**
 * 相信信息
 * @param id
 */
export function info (id) {
  const url = `/api/user/${id}`
  return request.get(url)
}

/**
 * 相信信息
 * @param id
 */
export function act (id) {
  const url = `/api/user/act/${id}`
  return request.post(url)
}
